home *** CD-ROM | disk | FTP | other *** search
- Path: news.umbc.edu!not-for-mail
- From: schlein@umbc.edu (Jonas J. Schlein)
- Newsgroups: comp.lang.c
- Subject: Re: How to use assert( )
- Date: 16 Apr 1996 14:16:03 -0400
- Organization: University of Maryland Baltimore County
- Message-ID: <4l0o53$74s@umbc9.umbc.edu>
- References: <4kc3k7$dur@orion.cybercom.net>
- NNTP-Posting-Host: umbc9.umbc.edu
- NNTP-Posting-User: schlein
-
- John Nield <nield@cybercom.net> wrote:
- |> I am interested in the use of the assert() library function (macro?).
- |> Neither the FAQ, nor K&R seems to have anything about it. Could
- |> someone help me with a breif explanation of its uses and mabye some
- |> example code?
- |>
- |> I'm just starting my first project big enough to split among many
- |> people, and from the vague explanations I've heard, assert is supposed
- |> to be a usefull way to cause errors when someone passes your code bad
- |> values. How do I do this?
-
- Simply do an #include <assert.h> at the top of your code and then use
- assert (expr); wherever you want to test. Obviously expr is some boolean
- or logical expression. Should the assertion fail your program will and and
- print the expression it was passed as well as the line number and file.
-
- Not the best way to catch errors, but it's ok for cases you consider
- "impossible" to occur ;-).
- --
- "If it wasn't for C, we would be using BASI, PASAL, and OBOL."
-
- Jonas J. Schlein (schlein@gl.umbc.edu)
-